<?php

namespace app\models;

use app\components\BaseActiveRecord;
use Yii;

/**
 * This is the model class for table "{{%setting}}".
 *
 * @property string $id
 * @property string $val
 */
class Setting extends BaseActiveRecord {

    /**
     * @inheritdoc
     */
    public static function tableName() {
        return '{{%setting}}';
    }

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['id', 'val'], 'required'],
            [['val'], 'string'],
            [['id'], 'string', 'max' => 70],
            [['id'], 'unique'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'val' => 'Val',
        ];
    }

    public function access() {
        return $this->cache(function () {
            $settings = Setting::find()->asArray()->all();
            $data = [];
            foreach ($settings as $setting) {
                $data[$setting['id']] = $setting['val'];
            }
            return $data;
        });
    }
}
